﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace HostAssistantCore
{
	public class UtilFactory
	{
		public static IUtil GetUtil()
		{
			IUtil instance = null;

			int majorVersion = Convert.ToInt32(GetIISMajorVersion());
			switch(majorVersion)
			{
				case 6:
					instance = new UtilForIIS6();
					break;
				case 7:
				case 8:
                case 9:
                case 10:
					instance = new UtilForIIS7();
					break;
			}

			return instance;
		}
        /// <summary>
        /// 获取IIS版本
        /// </summary>
        /// <returns></returns>
        public static double GetIISMajorVersion()
		{
			double majorVersion = 0;

			try
			{
				var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\INetStp");
                if (key != null)
					majorVersion = Convert.ToDouble(key.GetValue("MajorVersion"));
			}
			catch{}

			return majorVersion;
		}
        public static int IISTouch()
        {
            int rt = 0;
            int majorVersion = Convert.ToInt32(GetIISMajorVersion());
            switch (majorVersion)
            {
                case 6:
                    rt = 1;
                    break;
                case 7:
                case 8:
                case 9:
                case 10:
                    rt = 2;
                    break;
            }
            return rt;
        }
	}
}
